package cn.edu.ctbu.studentweb.service;


import cn.edu.ctbu.studentweb.domain.Student;
import cn.edu.ctbu.studentweb.repository.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class StudentService {

    @Autowired
    private static StudentRepository studentRepository = null;

    public StudentService(StudentRepository studentRepository) {
        this.studentRepository = studentRepository;
    }


    public List<Student> findAll() {
        return studentRepository.findAll();
    }

    public Student findById(int id) {
        return studentRepository.findById(id).orElse(null);
    }
    public void delete(Integer id){
        studentRepository.deleteById(id);
    }


    public Student insert(Student student) {  return studentRepository.save(student);
    }

    public Student getById(Integer id) {
        Student student=studentRepository.findById(id).orElse(null);
        return student;
    }
    public static Student update(Student student) {
        return studentRepository.save(student);
    }
}

